package com.fm.financemanage.controller;


import com.fm.financemanage.component.TokenComponent;
import com.fm.financemanage.constant.PlatTypeEnum;
import com.fm.financemanage.constant.ResponseEnum;
import com.fm.financemanage.exception.ParameterException;
import com.fm.financemanage.model.vo.PageVo;
import com.fm.financemanage.model.vo.company.CompanyAccountConfigOperatorVo;
import com.fm.financemanage.model.vo.company.CustomerCompanyInfoListVo;
import com.fm.financemanage.model.vo.company.CustomerCompanyOperatorVo;
import com.fm.financemanage.model.vo.memberrecord.RsMemberRecordListVo;
import com.fm.financemanage.model.vo.memberrecord.YbMemberRecordListVo;
import com.fm.financemanage.response.Callback;
import com.fm.financemanage.response.JsonData;
import com.fm.financemanage.service.CustomerCompanyInfoService;
import com.fm.financemanage.service.MemberRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RequestMapping("/member/record")
@Api(tags = "客户信息管理")
@RestController
@Validated
public class MemberRecordController {


    @Autowired
    private MemberRecordService memberRecordService;

    @Autowired
    private TokenComponent tokenComponent;

    @GetMapping("/rs")
    @ApiOperation("查询rs增减员列表")
    public JsonData<PageVo<List<RsMemberRecordListVo>>> getRsList(HttpServletRequest request, HttpServletResponse response,
                                                                  @ApiParam(name = "type", value = "add,reduce", required = true)
                                                                  @RequestParam(name = "type", required = false) String type,
                                                                  @ApiParam(name = "accountantId", value = "会计员Id", required = true)
                                                                  @RequestParam(name = "accountantId", required = false) Integer accountantId,
                                                                  @ApiParam(name = "state", value = "0 失败 1 成功", required = true)
                                                                  @RequestParam(name = "state", required = false) Integer state,
                                                                  @ApiParam(name = "companyId", value = "公司id", required = true)
                                                                  @RequestParam(name = "companyId", required = false) Integer companyId,
                                                                  @ApiParam(name = "certno", value = "证件号码", required = true)
                                                                  @RequestParam(name = "certno", required = false) String certno,
                                                                  @ApiParam(name = "page", value = "页码", required = true)
                                                                  @RequestParam(name = "page", required = false) Integer page,
                                                                  @ApiParam(name = "limit", value = "条数", required = true)
                                                                  @RequestParam(name = "limit", required = false) Integer limit
    ) {
        Long id = tokenComponent.getUserId(request);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), memberRecordService.getRsList(id, type, state, accountantId, companyId,
                certno, page, limit));
    }


    @GetMapping("/yb")
    @ApiOperation("查询yb增减员列表")
    public JsonData<PageVo<List<YbMemberRecordListVo>>> getYbList(HttpServletRequest request, HttpServletResponse response,
                                                                  @ApiParam(name = "type", value = "add,reduce", required = true)
                                                                  @RequestParam(name = "type", required = false) String type,
                                                                  @ApiParam(name = "accountantId", value = "会计员Id", required = true)
                                                                  @RequestParam(name = "accountantId", required = false) Integer accountantId,
                                                                  @ApiParam(name = "state", value = "0 失败 1 成功", required = true)
                                                                  @RequestParam(name = "state", required = false) Integer state,
                                                                  @ApiParam(name = "companyId", value = "公司id", required = true)
                                                                  @RequestParam(name = "companyId", required = false) Integer companyId,
                                                                  @ApiParam(name = "certno", value = "证件号码", required = true)
                                                                  @RequestParam(name = "certno", required = false) String certno,
                                                                  @ApiParam(name = "page", value = "页码", required = true)
                                                                  @RequestParam(name = "page", required = false) Integer page,
                                                                  @ApiParam(name = "limit", value = "条数", required = true)
                                                                  @RequestParam(name = "limit", required = false) Integer limit
    ) {
        Long id = tokenComponent.getUserId(request);

        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), memberRecordService.getYbList(id, type, state, accountantId, companyId,
                certno, page, limit));
    }

    @DeleteMapping("/{type}/{id]")
    @ApiOperation("查询yb增减员列表")
    public JsonData<PageVo<List<YbMemberRecordListVo>>> remove(HttpServletRequest request, HttpServletResponse response,
                                                               @ApiParam(name = "type", value = "fj_RS,fj_YB", required = true) @PathVariable("type") String type,
                                                               @PathVariable("id") Integer id
    ) {
        Long userId = tokenComponent.getUserId(request);
        memberRecordService.remove(userId, type, id);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());
    }

}
